﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class api_generalConfigList : PageBase
{
    generalConfigList bll = new generalConfigList();
    string baseName = "配置";
    protected void Page_Load(object sender, EventArgs e)
    {
        ResponseData rd = isLogin();
        if (rd.code != 1)
        {
            Json(rd);
            return;
        }
        string action = Request["action"];
        switch (action)
        {
            case "GetConfig"://获取配置 
                GetConfig();
                break;
            case "Update"://更新一条 
                Update();
                break;
            default:
                break;
        }
    }

    private void GetConfig()
    {
        ResponseData rd = new ResponseData();
        try
        {
            Hashtable h_p = getPostParameter_json();
            Hashtable h_param = new Hashtable();
            h_param["cName"] = h_p["cName"];
            Hashtable h_model = bll.GetModel(h_param);
            rd.data = h_model;
            rd.code = h_model.Count > 0 ? 1 : 0;
            rd.message = h_model.Count > 0 ? "获取" + baseName + "成功！" : baseName + "获取失败!";
        }
        catch (Exception ex)
        {
            rd.code = -1;
            rd.message = "出错啦！错误详情：" + ex.Message;
        }
        Json(rd);
    }

    private void Update()
    {
        ResponseData rd = new ResponseData();
        try
        {
            Hashtable h_p = getPostParameter_json();
            if (h_p["id"] == null) // 新增
            {
                //Hashtable h_param = new Hashtable();
                //h_param["code"] = h_p["code"];
                //h_param["userNum"] = h_p["userNum"];
                //Hashtable h_model = bll.GetModel(h_param);
                //int i = 0;
                //if (h_model.Count == 0)
                //{
                //    h_p["updateTime"] = ""; //更新时间
                //    h_p["createTime"] = GetDateTimeString(); //创建时间
                //    i = bll.Insert(h_p);
                //}
                //rd.code = i > 0 ? 1 : 0;
                //rd.message = i > 0 ? "添加" + baseName + "成功！" : "添加" + baseName + "失败! 可能已存在";
            }
            else // 修改
            {
                h_p["updateTime"] = GetDateTimeString(); //更新时间
                if (h_p.Contains("createTime"))
                {
                    h_p.Remove("createTime");
                }
                int i = bll.Update(h_p);
                rd.code = i > 0 ? 1 : 0;
                rd.message = i > 0 ? "更新" + baseName + "成功！" : "更新" + baseName + "失败!";
            }
        }
        catch (Exception ex)
        {
            rd.code = -1;
            rd.message = "出错啦！错误详情：" + ex.Message;
        }
        Json(rd);
    }

}